#
# from scrapy import cmdline
#
#
# if __name__ == '__main__':
#     cmdline.execute("scrapy crawl FutianTeacherSpider".split())
from apscheduler.schedulers.blocking import BlockingScheduler
from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings

from goodDesignImage2018Spider.job.downloadGoodDesignImgJob import downloadGoodDesignImgJob


# 启动爬虫
def start_crawl(b):
    if b:
        process = CrawlerProcess(get_project_settings())
        for spider_name in process.spider_loader.list():
            if spider_name == "meishijDetailSpider":
                process.crawl(spider_name)
        process.start()


# 启动定时器下载爬的图片
def start_download_job(b):
    if not b:
        return
    scheduler = BlockingScheduler()
    # 向调度器中添加定时任务
    scheduler.add_job(call_download_method, 'cron', second='*/59')
    # 启动定时任务调度器工作
    scheduler.start()


def call_download_method():
    job = downloadGoodDesignImgJob()
    job.download_record()


if __name__ == '__main__':
    start_crawl(True)
    start_download_job(False)
